package com.bupt.ilink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bupt.ilink.entity.Studyspace.StudyTeacherCourse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StudyTeacherCourseMapper extends BaseMapper<StudyTeacherCourse> {
    @Select("SELECT * FROM study_teacher_courses WHERE course_id = #{courseId}")
    StudyTeacherCourse getCourseById(@Param("courseId") Long courseId);

    @Select("SELECT * FROM study_teacher_courses WHERE teacher_id = #{teacherId}")
    List<StudyTeacherCourse> getCourseByteacherId(@Param("teacherId") String teacherId);

    @Select("SELECT course_tag FROM study_teacher_courses " +
            "GROUP BY course_tag " +
            "ORDER BY COUNT(*) DESC " +
            "LIMIT 8")
    List<String> getCommonTags();

    @Update("UPDATE study_teacher_courses SET view_num = view_num + 1 WHERE course_id = #{course_id}")
    void incrementViewNum(@Param("course_id") String course_id);

    @Update("UPDATE study_teacher_courses SET folder_id = NULL WHERE course_id = #{courseId}")
    int clearFolderIdByCourseId(@Param("courseId") Long courseId);
}
